www.gusucode.com > 关于海航matlab和lingo的训练题 > 人脸检测/face detection/isThisAFace.m
function [autocorr, startx, starty, mfit, bwmodel_rot] = isThisAFace(mult, model,ly,wx,cx, ... cy, angle) model_rot = imrotate(model,-angle,'bilinear'); % Use the frontal model to do the comparison % model_rot = imresize(model_rot,[ly wx],'bilinear'); [l,r,u,d] = recsize(model_rot); model_rot=imcrop(model_rot,[l u (r-l) (d-u)]); % figure; % imshow(model_rot); bwmodel_rot = zeros(size(model_rot)); bwmodel_rot(find(model_rot > 1))=1; % Compute the center of the rotated face model [modx,mody] =center(bwmodel_rot); % Get the size of the rotated face model [morig, norig] = size(bwmodel_rot); startx = cx-modx; starty = cy-mody; endx = startx + norig-1; endy = starty + morig-1; mfit = zeros(size(mult)); mfitbw = mfit & 0; [limy, limx] = size(mfit); startx = checklimit(startx,limx); starty = checklimit(starty,limy); endx = checklimit(endx,limx); endy = checklimit(endy,limy); % ------------------------------------------------------------- % The following is to generate a new image having the same % size as the original one, but with the face of the model on it % rotated accordingly. for i=starty:endy, for j=startx:endx, mfit(i,j) = model_rot(i-starty+1,j-startx+1); mfitbw(i,j) = mfit(i,j); end; end; figure; imshow(mfit,[0 255]); % Get the autocorrelation value autocorr = corr2(mfit,mult) % Verifies that the coordinate is between the image region. function newcoord = checklimit(coord,maxval) newcoord = coord; if (newcoord<1) newcoord=1; end; if (newcoord>maxval) newcoord=maxval; end; % EOF.